home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu330.dms
/
pu330.adf
/
SafeDelete
/
SafeDelete.doc
< prev
next >
Wrap
Text File
|
1992-09-14
|
16KB
|
372 lines
SAFE DELETE
~~~~~~~~~~~~~
©Copyright Chris Watson 1992
1. Summary
~~~~~~~~~~
This program provides a patch for the AmigaDOS library delete function
so that any deletions operate in a similar manner to the workbench
Trashcan. When a file is deleted it is moved into a trashcan
directory from where it can later be deleted. A list of files can be
specified, using the full pattern matching system which are actually
deleted rather than moved. This program requires at least version
2.04 of kickstart and workbench.
2. Using Safe Delete
~~~~~~~~~~~~~~~~~~~~
2.1. Trashcan location
The trash directory can be placed anywhere and can be absolute,
relative to the volume or relative to the directory. Any relative
trashcans are relative to the file being deleted and not the current
directory of the calling program. The location is set using the
`TRASH' environment variable, simply use SetEnv to set this to the
required directory path, there is no need to end the path with a `/'.
If this variable does not exist then the default directory
`SYS:Trashcan' is used. If the specified directory does not exist
then it is created. The trashcan directory can be on any volume and
can be on a different volume to a file. My own preference is to use
one central directory, 'SYS:Trashcan', so I always know where a
deleted file will be and cleaning out the directory is made simpler
since there is only one. For maximum speed a RAM: or RAD: based
trashcan could be used which does reduce the lifetime of deleted files
to between reboots or power-downs. On a floppy based system you
should make the trashcan directory relative to the current volume,
otherwise a deletion will take far too long to be worthwhile.
2.2. Temporaries list
The temporaries list is a list of files which should be deleted
completely rather than being moved. This list consists of a set of
patterns against which the file is compared, if a match is made then
the file is deleted properly. This list includes not only files but
directories as well, thus files in a temporary directory such as T:
or trashcan can be deleted, as normal. This temporary list is
entirely at the discretion of the user, if no patterns are placed in
it then all files are moved, including files, which are already in the
trashcan directory. The included .info sets the temporary files and
directories which I use, the command line given under installation
gives the same set of patterns from the command line.
The pattern match is case-less and before being matched the file name
is expanded to an absolute path, which includes the volume name and
not the drive name, i.e. floppy:file rather than df0:file or
RAMDISK:T/tmp rather than T:tmp. This means that the temporaries list
needs to specify only the one absolute path against which it can be
compared rather than a number of relative paths.
When inserting a directory or file into the temporary list the
possible locations it may exist in and the way they interact with the
pattern matching techniques must be considered. For example, any file
which has an extension of .tmp may be detected if it is added to the
temporaries list as #?.tmp. However, any file which begins with
CygnusEd may only be detected by using all its possible paths i.e.
#?(/|:)CygnusEd is required, the same applies to directories. If you
are in any doubt as to which expansion to perform then simply use the
Add option from the windowing interface and examine the patterns that
it inserts, and if you wish insert them into your startup call to
SafeDelete.
2.3. Installation
The DeleteFile replacement function can be installed simply by running
the SafeDelete program from the CLI or Workbench. The program sets up
a list of temporaries and patches the dos library. The program does
not remain in memory, although the patch and temporaries list do, this
means that the memory overhead is small, about 1k. If you wish to run
SafeDelete at startup time, which is the best time to run it, then
either drop it into the WBStartup drawer or place it into your
User-Startup file.
The initial temporaries list can be set easily. From the CLI type the
file name and path and the list of temporaries to use, as an example,
to get the same set of temporaries as the included .info file:
SafeDelete #?.tmp #?(:|/)T/#? #?(/|:)Trashcan/#? #?(:|/)CygnusEd?.???
To setup the initial temporaries list from the Workbench add each item
as a tool type they can be entered directly e.g. #?.tmp or with an
initial ADD='s statement, thus ADD=#?.tmp.
The method that SafeDelete uses to ascertain if the library has
already been patched by SafeDelete is to check for the existence of
the `SafeDelete' environment variable. If your environment directory
is permanent, whether between cold reboots or full power-downs, then
the program will only be installed once. To get round this the FORCE
keyword can be used, it can be specified on the CLI command line, as
FORCE, or in the workbench tool types, as FORCE=. If the force
keyword occurs in the arguments to the SafeDelete program then it will
always patch the dos library.
2.4. CLI Interface
If SafeDelete is invoked from the CLI or shell then it has the
following template, giving a question mark, ?, as an option brings up
this template and doing so again brings up further help:
SafeDelete KILL/S,FORCE/S,ADD/M,REMOVE/F/K
SafeDelete performs a range of possible actions based upon the command
line options and whether or not it is already installed. If it is not
already installed or the FORCE option is specified, then it installs
itself and uses the arguments to ADD, which are optional, as the
initial temporaries list.
If KILL is specified and it is already installed then it will attempt
to remove the patch from the dos library and deallocates the memory
used. Care must be taken that no programs are currently executing the
Safe Delete code and no other instances of SafeDelete or its child
processes are running, but see also the section on other dos library
patching programs. If ADD is specified, and/or one or more patterns
are given, then the patterns are inserted into the temporaries list.
Note unlike the Window Add option this inserts only the specified
patterns it does not expand them in any way.
If REMOVE is specified then any patterns following the REMOVE keyword
are deleted from the temporaries list. If you wish to delete patterns
then REMOVE must be specified and as can be seen from the template the
REMOVE option absorbs anything on the command line after it, so REMOVE
and its patterns should always be specified last.
Finally, if no options are specified and the patch has already been
installed then the windowing interface is called and the program
detaches from the CLI, allowing it to be closed or other programs to
be run from it.
2.5. Workbench Interface
SafeDelete can be called from the Workbench, if it is not installed or
the FORCE tool type is specified then it uses the tool types as a set
of initial temporaries, again like the CLI ADD argument, these are not
expanded in any way.
If the program has already been installed then the windowing interface
is opened. In this case the tool types are ignored.
2.6. Windowing Interface
The windowing interface offers an interactive means of controlling and
examining the temporaries list and of removing the patch. It is
started from the workbench any time that the SafeDelete program is
run, the patch has already been applied and there is no FORCE tool
type. From the CLI it is started if there are no command line options
and the patch has already been applied.
The window which opens has a list gadget which contains a list of all
the temporary patterns and four gadgets; Add, Remove, Done and Kill.
The Done gadget closes the window and exits the program, the window
close gadget also has the same effect. The Kill gadget removes the
patch and exits the program. The Remove gadget is ghosted until a
pattern entry is selected, the selected entry will then appear in the
box below the main list and clicking on remove will delete it from the
temporaries list.
The Add gadget is used to add new pattern entries into the temporaries
list, when it is clicked an file requester will appear. Select the
file patterns from the requester or type them into the string gadgets,
wildcards may be entered by typing them into the string gadgets. A
filename, a directory or both a filename and a directory may be
entered, the program will then expand the entered pattern to account
for all delete possibilities.
2.7. Cleaning out the Trashcan directory
No special tools are required to delete the contents of your trashcan
directory, all that is required is for the directory to be included as
part of the temporaries list then any delete program will correctly
delete the contents. If you wish to empty the contents on startup
simply insert:
delete SYS:Trashcan/#? ALL QUIET
in your User-Startup either before or after SafeDelete has been
installed or alternatively PurgeTrash can be used, in order to limit
the growth of the trashcan.
3. Other Programs
~~~~~~~~~~~~~~~~~
3.1. WildStar
WildStar allows the asterisk, *, to be used as a wildcard in place of
the #? wildcard. Invoking WildStar toggles the status of the *, so
that one use will allow it and the next will stop its use. Since, the
Shell uses * to represent the current console, an asterisk on its own
will still refer to the rather than the list of files, thus type *
will allow input to be typed in the console which is echoed, rather
than typing the contents of all the files in the current directory as
#? would. The star can be used in normal directory paths such as /*
with no problems, but if it's used on its own then two should be used
i.e. ** is the same as #?, whilst :* is the same as :#?.
3.2. PurgeTrash
PurgeTrash is used to delete the contents of the trashcan, files are
deleted based on their age, the size of the trashcan or both. It uses
the following template:
SIZE/N,DAYS/N,DIR/S,CONTINUE/S
If a size is given then files are deleted, oldest first, from the
trashcan in order to reduce it to that size, in bytes. For example:
PurgeTrash SIZE 1000000
would restrict the trashcan to a size of 1 megabyte. If days is given
then files older than that date are deleted, for example:
PurgeTrash DAYS 7
would delete all the files in a trashcan over 1 week old. If both are
given then it deletes only files older than the specified date and
which cause the trashcan to be larger than the specified size. For
example:
PurgeTrash SIZE 1000000 DAYS 7
would delete all the files in the trashcan which are over 1 week old
and which caused the trashcan to be too large. It would not, however,
delete files which were less than 7 days old even if the trashcan was
too big. Thus, files may be present in the trashcan which are older
than expected and the trashcan may be larger than expected. If the
DIR switch is present then any empty directories will be deleted, this
occurs during the scanning phase, so directories which are emptied as
the result of deletions by this program are ignored, however, they
will be deleted the next time PurgeTrash is run. If the CONTINUE
switch is present then the program will continue if a file fails to
delete, although it is considered to have been deleted for the
purposes of reducing the size of the trashcan. The program to
defaults to deleting all files over 7 days old, not deleting empty
directories and stopping on an error.
The program can also be called from the workbench, all the command
line arguments are supported as tool types, so `SIZE=<num>',
`DAYS=<num>', `DIR' and `CONTINUE' can all be present as tool types.
3.3. RetTrash
RetTrash retrieves a file from the trashcan, its template is:
FROM/M,TO/A,ALL/S,BUF=BUFFER/K/N,QUIET/S
FROM is a list of files which are to be retrieved, sub-directories
within the trashcan may be specified and wildcards may be used for the
name of the file, although not for any directory specifier. TO
indicates to which directory/filename the file is to be moved,
wildcards are not supported for this argument "" and a single dot `.'
can be used to represent the current directory and two dots `..' can
be used to represent the parent directory. ALL indicates that a full
directory structure should be moved, if ALL is not present then
directories are ignored. BUFFER gives the size of buffer to use in
512 byte blocks. By default 200 blocks are used, 100k, if buffer is 0
then a buffer the same size as the file is allocated. If QUIET is
present then messages indicating the status of the retrieval are not
displayed although error messages are. The program also copies the
date, protection bits and comments of the trashcan file.
It should be emphasised that the files in the trashcan are normal
AmigaDOS files and both RetTrash and PurgeTrash are provided as
convenient tools for accessing the trashcan, it is not necessary to
use them.
4. Notes
~~~~~~~~
4.1. Other Dos library patching programs
There are other programs which patch dos library, such as SnoopDos,
this patch should be transparent to them; but the patches should be
removed in reverse order to their order of insertion. So, if SnoopDos
is run before SafeDelete, then SafeDelete must be killed before
SnoopDos.
4.2. Pre-v2 Filing Systems
The SafeDelete patch users the NameFromLock function, some filing
systems which pre-date version 2 do not support this, such as
MessyDos. In such cases the file will be deleted but the patterns may
not work the way you expect, since the major effect of the lack of
this call is that filenames are not expanded to their full and correct
absolute path. The files are deleted based on the name passed by the
calling program, in the case of the Dos Delete command only the file
name is passed in, thus any paths in the pattern will probably be
ignored.
4.3. Compressing this Program
If you are using a floppy based system then it is worth crunching the
SafeDelete program using a utility such as PowerPacker or Imploder.
Simple tests indicate that PowerPacker v3.0b in it's best mode is
better than Imploder v4.0. Both of them do reduce file size and
loading time.
4.4. Deletion Programs
The patch works with any program which performs deletions through the
Dos Library delete function call; such as SID, DirWork and the
ToolManager DeleteTool program, but not the 1.3 Delete command. As an
added bonus to users of Cygnus Ed if a file is saved using the `safe
save' option then the previous version is automatically backed up,
which reduces the clutter of .bak files which occur with the normal
backup option.
5. Distribution and Contribution
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This program is shareware and a fee of £5 (sterling) is charged for
usage after a 30 day evaluation period.
It can be distributed for no more than a nominal fee which covers
distribution and copying. This program may be included in any
library, specific permission is given for its inclusion in the Fred
Fish library. The distribution set of files may not be changed.
6. Acknowledgements
~~~~~~~~~~~~~~~~~~~
Thanks to Steve Watts for the original inspiration for this program on
Unix and Uwe Schuerkamp for nodelete which showed that patching the
dos library was feasible.
Eddy Carroll whose subroutine Res.a provided the means of writing the
subroutine which allowed SafeDelete to detach itself.
7. Addresses
~~~~~~~~~~~~
Email as:
cw@olympus.cs.hull.ac.uk - preferable
or
cwatson@compulink.co.uk
Normal mail as, although email is far more convenient:
Chris Watson
82a Morthen Road,
Wickersley,
Rotherham,
South Yorkshire,
S66 0EG,
Britain.